package com.ailot.cloud.mall.controller;

import com.ailot.cloud.base.common.dto.Result;
import com.ailot.cloud.base.log.annotation.Oplog;
import com.ailot.cloud.mall.entity.GoodsSpecValue;
import com.ailot.cloud.mall.service.GoodsSpecValueService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 规格值表
 *
 * @Author ailot
 * @create 2024-06-30
 */

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/goodsspecvalue")
public class GoodsSpecValueController {

    private final GoodsSpecValueService goodsSpecValueService;

    /**
     * 分页
     */
    @GetMapping("/page")
    @PreAuthorize("hasAuthority('mall:goodsspecvalue:page')")
    public Page<GoodsSpecValue> getGoodsSpecValuePage(Page<GoodsSpecValue> page, GoodsSpecValue goodsSpecValue) {
        return goodsSpecValueService.page(page, Wrappers.query(goodsSpecValue));
    }

    /**
     * 新增
     */
    @Oplog("新增")
    @PostMapping
    @PreAuthorize("hasAuthority('mall:goodsspecvalue:add')")
    public Boolean save(@Valid @RequestBody GoodsSpecValue goodsSpecValue) {
        return goodsSpecValueService.save(goodsSpecValue);
    }

    /**
     * 修改
     */
    @Oplog("修改")
    @PutMapping
    @PreAuthorize("hasAuthority('mall:goodsspecvalue:edit')")
    public Boolean update(@Valid @RequestBody GoodsSpecValue goodsSpecValue) {
        return goodsSpecValueService.updateById(goodsSpecValue);
    }

    /**
     * 删除
     */
    @Oplog("删除")
    @DeleteMapping("/{id}")
    @PreAuthorize("hasAuthority('mall:goodsspecvalue:del')")
    public Result delete(@PathVariable String id) {
        return Result.success(goodsSpecValueService.removeById(id));
    }


}